class TicTacToe(object):

    def __init__(self, n):
        """
        :type n: int
        """
        self.h = [[0 for _ in range(n)] for _ in range(2)]
        self.v = [[0 for _ in range(n)] for _ in range(2)]
        self.l_1 = [0] * 2
        self.l_2 = [0] * 2
        self.n = n

    def move(self, row, col, player):
        """
        :type row: int
        :type col: int
        :type player: int
        :rtype: int
        """
        player = player - 1
        self.h[player][row] += 1
        if self.h[player][row] == self.n:
            return player + 1
        self.v[player][col] += 1
        if self.v[player][col] == self.n:
            return player + 1
        if row == col:
            self.l_1[player] += 1
        if self.l_1[player] == self.n:
            return player + 1
        if row + col == self.n - 1:
            self.l_2[player] += 1
        if self.l_2[player] == self.n:
            return player + 1
        return 0
